#include "../inc/my_game.h"
#include "../inc/bmp.h"
#include "../inc/my_thread.h"
#include "../inc/touch.h"




void game_show(){
    //展示游戏背景图片
    bmp_show("./res/interface/game_background.bmp",0,0);
    //左移右移攻击贴图
    bmp_show_small("./res/interface/left_move.bmp",0,400);
    bmp_show_small("./res/interface/right_move.bmp",80,400);
    bmp_show_small("./res/interface/player_attack.bmp",720,400);
    //退出按钮
    bmp_show_small("./res/interface/mainExit.bmp",700,0);
}

void game_play(){
    int x = 0;
    int y = 0;
    int flag_acc_pd = 0;
    //起始账号栏x坐标
    int realTimeacc_X = 400;
    //起始密码栏x坐标
    int realTimeX = 400;

    //初始化游戏状态
    monster_status = 1;
    player_action = 1;
    player_location = 0;
    player_atk = 0;
    monster_blood = 4;

    //开启怪物动态线程
    pthread_t thread_monster_dynamic;
    pthread_create(&thread_monster_dynamic,NULL,monster_dynamic,NULL);
    //开启玩家动态线程
    pthread_t thread_player_dynamic;
    pthread_create(&thread_player_dynamic,NULL,player_dynamic,NULL);
    //开启玩家攻击线程
    pthread_t thread_player_accack;
    pthread_create(&thread_player_accack,NULL,player_attack,NULL);
    while(1){
        //获取按键上的坐标
        touch_wait(&x,&y);
        if(PLACE_GAME_PLAYER_LEFT(x,y)){
            player_action = 2;
            player_location = player_location - 40;
            printf("点击了左移\n");
        }
        if(PLACE_GAME_PLAYER_RIGHT(x,y)){
            player_action = 1;
            player_location = player_location + 40;
            printf("点击了右移\n");
        }
        if(PLACE_GAME_PLAYER_ATTACK(x,y)){
            player_atk = 1;
            if((player_location+140+80)>690){
                monster_blood --;
                monster_status = 2;
            }
            if(monster_blood == 0){
                monster_status = 3;
                usleep(1500000);
                //线程全关了
                monster_status = -1;
                player_action = -1;
                player_atk = -1;
                break;
            }
            printf("点击了攻击\n");
        }
        if(PLACE_GAME_PLAYER_EXIT(x,y)){
            //线程全关了
            monster_status = -1;
            player_action = -1;
            player_atk = -1;
            printf("点击了退出\n");
            break;
        }

    }
}